<?php

namespace App\Http\Controllers\Console;

use Illuminate\Http\Request;
use App\Model\Common\UserLog;

class ProjectHistoryController extends CommonController
{
    protected $modelName = 'ProjectHistory';

    public function edit(Request $request)
    {
        $project_id = $request->input('project_id');
        if (!$project_id) {
            return $this->output(10005, '非法ID', null);
        }
        $m = model($this->modelName);

        $data = $request->post();
        if (!empty($this->RULE['update'])) {
            $validator = Validator::make($data, $this->RULE['update']);

            if ($validator->fails()) {
                return $this->output(10005, $validator->errors(), $data);
            }
        }

        $data = $this->requestDataFormat($data);
        if (method_exists($m, 'edit')) {
            $re = $m->edit($data);
        }

        if (false !== $re) {
            if (method_exists($m, 'refreshCache')) {
                $m->refreshCache($request, 'update');
            }
            UserLog::log($request, $m);

            return $this->output(0, '更新成功', null);
        } else {
            return $this->output(10001, '更新失败'.$m->getError(), $data);
        }
    }
}
